#ifndef __SPEAKMANAGER_H__
#define __SPEAKMANAGER_H__

#include "MyThread.h"
#include "Com.h"
#include <stdio.h>

class IOSpeakRecvNotify
{
public:
	IOSpeakRecvNotify(void){};
	virtual~IOSpeakRecvNotify(void){};
public:
	virtual void OnRecvDataNotify(const char *szBuf, int nLen) = 0;
};

class CSpeakManager : public CMyThread
{
public:
	CSpeakManager(IOSpeakRecvNotify *pNotify);
	~CSpeakManager(void);

	bool Start(int nComId);
	void Stop(void);

	bool GetSpeakStatus(void);
	bool GetSpeakIsOK(void);

	bool SetSpeakID(int nSpeakId);
	bool OpenSpeak(void);

	bool GetSpeakId(void);

	bool IsConnect(void);
	int SendDataToSpeak(const char *pData, int nDataLen);

protected:
	virtual void ThreadProcMain(void);

private:
	bool OpenCom(int nComId);
	void CloseCom(void);

	int ReadDataFromSpeak(char *pBuff, int nBuffLen);
	void CheckRecvData(void);

private:
	bool				m_bExit;
	bool				m_bOpenStatus;

	bool				m_bFrist;

	int					m_nComId;
	CCom				m_cCom;

	char				*m_pRecvData;
	int					m_nRecvDataLen;

	int					m_nCurrentRecvLen;
	IOSpeakRecvNotify	*m_pNotify;

	FILE					*m_pOutFile;
};

#endif
